﻿@{
    ViewBag.Title = "Form";
    Layout = "~/Views/Shared/_FlowIndex.cshtml";
}
<script src="~/Content/scripts/jquery/layer/jquery.js?v=1.83.min"></script>
<script src="~/Content/scripts/jquery/layer/layer.min.js"></script>
<link href="~/Content/styles/font-awesome.min.css" rel="stylesheet" />
<link href="~/Content/styles/BillDetail.css?v=1.1" rel="stylesheet" />
<link href="~/Content/styles/anitmate.css" rel="stylesheet" />
<link href="~/Content/styles/style.css" rel="stylesheet" />

<link href="~/Content/scripts/plugins/tree/tree.css" rel="stylesheet" />
<link href="~/Content/scripts/plugins/jqgrid/jqgrid.css" rel="stylesheet" />
<script src="~/Content/scripts/plugins/tree/tree.js"></script>

<script src="/Content/scripts/plugins/validator/js?v=XgpF3bkqcHESsLip2j1dhS6n2I-zHyD2VCazpanqH6Q1"></script>
<script src="/Content/scripts/utils/js?v=FNqaC7G7A87_J4VCIQpQEAO-d_2Qf2wSxoZexwRzulo1"></script>
<script src="~/Content/scripts/plugins/jqgrid/jqgrid.js"></script>
<link href="~/Content/styles/LeSoft-report.css" rel="stylesheet" />
<link href="~/Content/styles/LeSoft-bill.css" rel="stylesheet" />
<script>
    var keyValue = request('keyValue');
    var _organizeid = "@LeSoft.Application.Code.OperatorProvider.Provider.Current().CompanyId";
    var selectedRowIndex = 0;
    $(function () {
        initControl();
    });

    function initControl() {

        $("#wrapper").css("width", "98%").css("padding", "0px").css("height", "98%");
        $(window).resize(function (e) {
            window.setTimeout(function () {
                $('#gridTable').setGridWidth(($('.panel-Title').width()));
                $('#gridTable').setGridHeight(($(window).height() - 401.5));
                $('#gridTable1').setGridHeight(($(window).height() - 71.5));
            }, 200);
            e.stopPropagation();
        });
        var Mode = "@ViewBag.Mode";
        if (Mode == "True") {
            $("#Code").attr("placeholder", "系统已启用自动编号").attr("disabled", "disabled");
        } else {
            $("#Code").attr("isvalid", "yes").attr("checkexpession", "NotNull").attr("placeholder", "请输入编号");
        }
        $(".completetr").removeAttr("disabled");
        //绑定组织机构
        $("#OrganizeId").ComboBoxTree({
            url: "../../BaseManage/Organize/GetTreeJson",
            description: "==请选择所属机构==",
            height: "250px",
            click: function (data) {
                _organizeid = data.id;
            }
        });
        if (_organizeid != "") $("#OrganizeId").ComboBoxTreeSetValue(_organizeid);

        $("#Person").attr("disabled", "disabled");
        $("#SendWay").ComboBox({
            data: [{ "key": 1, "value": "线下处理" }, { "key": 11, "value": "线上派给派单人" }, { "key": 12, "value": "线上派给抄表人" }],
            id: "key",
            text: "value",
            description: null,
            click: function (e) {
                if (e.attr('data-value') != 1) {
                    $(".on-line").removeAttr("hidden");
                    $(".Offline").attr("disabled", "disabled");
                }
                else {
                    $(".on-line").attr("hidden", "hidden");
                    $(".Offline").removeAttr("disabled");
                }
            }
        });
        $("#SendWay").ComboBoxSetValue(1);

        $("#State").ComboBox({
            data: [{ "key": 1, "value": "待处理" }, { "key": 2, "value": "派单中" }, { "key": 3, "value": "进行中" }, { "key": 4, "value": "已完成" }, { "key": 5, "value": "已提交" }, { "key": 6, "value": "审核通过" }, { "key": 7, "value": "审核不通过" }, { "key": 8, "value": "已驳回" }, { "key": 9, "value": "已取消" }],
            id: "key",
            text: "value",
            description: "==请选择=="
        });
        $("#State").ComboBoxSetValue(1);

        GetGrid();

        if (!!keyValue) {
            $.SetForm({
                url: "../../PropertyManage/CS_EnergyMeterReading/GetFormInfo",
                param: { keyValue: keyValue },
                success: function (data) {
                    $("#BaseInfo").SetWebControls(data.Bill);
                    $("#SendMan").attr("title", data.Bill.SendManId);
                    $("#ReceiveMan").attr("title", data.Bill.ReceiveManId);
                    GetGridAudit();
                    if (!!data.Bill.OperatorMemo)
                        GetGridOperatorMemo(eval("[" + data.Bill.OperatorMemo + "]"));
                    if (data.Bill.State >= 2) {
                        $("#BaseInfo").find("input").attr("disabled", "disabled");
                        $("#BaseInfo").find("a").attr("disabled", "disabled");
                        $("#BaseInfo").find("div").attr("disabled", "disabled");
                        $("#BaseInfo").find("textarea").attr("disabled", "disabled");
                        $(".toolbar").attr("hidden", "hidden");
                        if (data.Bill.State >= 3 && data.IsDispose) {
                            $("#gridTable").GridUnload();
                            GetGrid1();
                            $(".Batch").removeAttr("hidden");
                            $("#BatchDateTime").removeAttr("disabled");
                            $("#Price").removeAttr("disabled");
                        }
                        else if (data.Bill.State >= 4) {
                            $("#gridTable").GridUnload(); GetGrid2(); $("#save").parent().css("display", "none");
                        }
                        if (data.Bill.State == 4) {
                            $("#submit").css("display", "block");
                            $("#save").parent().css("display", "block"); $("#save").css("display", "none");
                        }
                        else if (data.Bill.State == 2 && data.Bill.SendWay == 1) { $("#ReceiveMan").removeAttr("disabled").next().find("a").removeAttr("disabled"); $("#ReceiveDate").removeAttr("disabled"); }
                        else if (data.Bill.SendWay == 11) {
                            $("#Person").next().find("a").removeAttr("disabled");
                            if (data.Bill.State == 2 && data.IsSendWay) {
                                $("#SendWay").removeAttr("disabled");//派工方式
                                $("#SendWay").ComboBox({
                                    data: [{ "key": 11, "value": "线上派给派单人" }, { "key": 12, "value": "线上派给抄表人" }],
                                    id: "key",
                                    text: "value",
                                    description: null
                                });
                                $("#SendWay").ComboBoxSetValue(11);
                            }
                        }
                        else if (data.Bill.State == 3 && data.Bill.SendWay == 12) { $("#Person").next().find("a").removeAttr("disabled"); }
                        else if (data.Bill.State == 7 && data.Bill.SubmitManId == "@LeSoft.Application.Code.OperatorProvider.Provider.Current().UserId") {
                            $("#gridTable").GridUnload();
                            GetGrid1();
                            $(".Batch").removeAttr("hidden");
                            $("#BatchDateTime").removeAttr("disabled");
                            $("#Price").removeAttr("disabled");
                            $("#save").parent().css("display", "block");
                        } else if (data.Bill.State == 3 && data.Bill.SendWay == 1) {
                            $("#gridTable").GridUnload();
                            GetGrid1();
                            $(".Batch").removeAttr("hidden");
                            $("#BatchDateTime").removeAttr("disabled");
                            $("#Price").removeAttr("disabled");
                        }
                    }
                    $("#gridTable")[0].addJSONData(data.List);
                }
            });
        }
    }

    function DataItemSelect(type, obj) {
        if (!!$(obj).attr("disabled")) { return false; }
        if ($("#OrganizeId").attr('data-value') == undefined) {
            dialogMsg("请先选择机构", 0);
            return false;
        } else {
            var options = {};
            switch (type) {
                case 1: var data = [{ id: "Person", text: "", value: "" }];
                    options = {
                        category: 3,
                        type: 3,
                        organizeid: $("#OrganizeId").attr('data-value'),
                        data: data,
                        TopForm: "Tab"
                    };
                    break;
                case 2: {//派单人
                    var data = [{ id: "SendMan", text: "", value: "" }];
                    options = {
                        category: 2,
                        type: 3,
                        organizeid: $("#OrganizeId").attr('data-value'),
                        data: data,
                        TopForm: "Tab"
                    };

                }; break;
                case 3: {//执行人
                    var data = [{ id: "ReceiveMan", text: "", value: "" }];
                    options = {
                        category: 2,
                        type: 3,
                        organizeid: $("#OrganizeId").attr('data-value'),
                        data: data,
                        TopForm: "Tab"
                    };
                }; break;
            }
            DataItemClick(JSON.stringify(options));
        }
    }

    function GetGrid() {
        var $gridTable = $("#gridTable");
        $gridTable.jqGrid({
            datatype: "json",
            height: $(window).height() - 401.5,
            autowidth: true,
            unwritten: false,
            colModel: [
                { label: "Id", name: "Id", hidden: true },
                { label: "EnergyMeterInstanceId", name: "EnergyMeterInstanceId", hidden: true },
                { label: "EnergyMeterId", name: "EnergyMeterId", hidden: true },
                { label: "State", name: "State", hidden: true },
                { label: "PStructId", name: "PStructId", hidden: true },
                { label: "表编号", name: "Code", index: "Code", width: 100, align: "center", sortable: false },
                { label: "表名称", name: "Name", index: "Name", width: 100, align: "center", sortable: false },
                { label: "所属房产", name: "AllName", index: "AllName", width: 200, align: "center", sortable: false },
                { label: "位置描述", name: "PSMemo", width: 150, align: "left", sortable: false },
                { label: "上次抄表期间", name: "LastBatchDate", width: 100, align: "left", sortable: false },
                { label: "上次抄表时间", name: "LastScaleDate", width: 100, align: "left", sortable: false },
                { label: "上次抄表读数", name: "LastScaleNum", width: 100, align: "left", sortable: false },
            ],
            rowNum: "1000",
            rownumbers: true,
            shrinkToFit: false,
            editurl: "clientArray",
            onSelectRow: function () {
                $(".ui-state-highlight").css("background", "#337ab7").css("color", "#ffffff");
            },
        });
    }

    function GetGrid1() {
        var $gridTable = $("#gridTable");
        $gridTable.jqGrid({
            datatype: "json",
            height: $(window).height() - 401.5,
            autowidth: true,
            unwritten: false,
            colModel: [
                { label: "Id", name: "Id", hidden: true },
                { label: "EnergyMeterInstanceId", name: "EnergyMeterInstanceId", hidden: true },
                { label: "EnergyMeterId", name: "EnergyMeterId", hidden: true },
                { label: "State", name: "State", hidden: true },
                { label: "PStructId", name: "PStructId", hidden: true },
                { label: "表编号", name: "Code", index: "Code", width: 100, align: "center", sortable: false },
                { label: "表名称", name: "Name", index: "Name", width: 100, align: "center", sortable: false },
                { label: "所属房产", name: "AllName", index: "AllName", width: 200, align: "center", sortable: false },
                { label: "位置描述", name: "PSMemo", width: 150, align: "left", sortable: false },
                { label: "上次抄表期间", name: "LastBatchDate", width: 100, align: "left", sortable: false },
                { label: "上次抄表时间", name: "LastScaleDate", width: 100, align: "left", sortable: false },
                { label: "上次抄表读数", name: "LastScaleNum", width: 100, align: "left", sortable: false },
                {
                    label: "本次抄表期间", name: "BatchDate", width: 100, align: "left", sortable: false,
                    formatter: function (cellvalue, options, rowObject) {
                        return !!cellvalue ? cellvalue : $("#BatchDate").val();
                    }
                },
                {
                    label: "本次抄表时间", name: "ScaleDate", width: 100, align: "left", sortable: false,
                    formatter: function (cellvalue, options, rowObject) {
                        return !!cellvalue ? cellvalue : "@DateTime.Now.ToString("yyyy-MM-dd")";
                    },
                    editable: true, edittype: "text", editoptions: { onclick: "WdatePicker({})" },
                },
                { label: "本次抄表读数", name: "ScaleNum", width: 100, align: "left", sortable: false, editable: true, edittype: "text", editoptions: { onpropertychange: "onInputScaleNum(this)", oninput: "onInputScaleNum(this)" }, editrules: { custom: true, custom_func: ValidateTvalue } },
                { label: "用量", name: "Volume", width: 100, align: "left", sortable: false },
                {
                    label: "调整用量", name: "AdjustVolume", width: 100, align: "left", sortable: false, formatter: function (cellvalue, options, rowObject) {
                        return !!cellvalue ? cellvalue : 0;
                    }, editable: true, edittype: "text", editrules: { custom: true, custom_func: ValidateTvalue }
                },
                { label: "单价", name: "UnitPrice", width: 80, align: "left", sortable: false, editable: true, edittype: "text", editoptions: { onpropertychange: "onInputUnitPrice(this)", oninput: "onInputUnitPrice(this)" }, editrules: { custom: true, custom_func: ValidateTvalue } },
                { label: "金额", name: "Price", width: 100, align: "left", sortable: false, editable: true, edittype: "text", editrules: { custom: true, custom_func: ValidateTvalue } },
            ],
            rowNum: "1000",
            rownumbers: true,
            shrinkToFit: false,
            gridview: true,
            hidegrid: false,
            editurl: "clientArray",
            onSelectRow: function (rowid) {
                if (selectedRowIndex != rowid) {
                    if ($(".editable").length > 0 && !$gridTable.jqGrid('saveRow', selectedRowIndex, { "keys": true, "aftersavefunc": aftersavefunc })) { return false; }
                }
                $gridTable.editRow(rowid, { "keys": true, "aftersavefunc": aftersavefunc });
                selectedRowIndex = rowid;
                $(".ui-state-highlight").css("background", "#337ab7").css("color", "#ffffff");
            },
        });
    }

    function GetGrid2() {
        var $gridTable = $("#gridTable");
        $gridTable.jqGrid({
            datatype: "json",
            height: $(window).height() - 401.5,
            autowidth: true,
            unwritten: false,
            colModel: [
                { label: "Id", name: "Id", hidden: true },
                { label: "EnergyMeterInstanceId", name: "EnergyMeterInstanceId", hidden: true },
                { label: "EnergyMeterId", name: "EnergyMeterId", hidden: true },
                { label: "State", name: "State", hidden: true },
                { label: "PStructId", name: "PStructId", hidden: true },
                { label: "表编号", name: "Code", index: "Code", width: 100, align: "center", sortable: false },
                { label: "表名称", name: "Name", index: "Name", width: 100, align: "center", sortable: false },
                { label: "所属房产", name: "AllName", index: "AllName", width: 200, align: "center", sortable: false },
                { label: "位置描述", name: "PSMemo", width: 150, align: "left", sortable: false },
                { label: "上次抄表期间", name: "LastBatchDate", width: 100, align: "left", sortable: false },
                { label: "上次抄表时间", name: "LastScaleDate", width: 100, align: "left", sortable: false },
                { label: "上次抄表读数", name: "LastScaleNum", width: 100, align: "left", sortable: false },
                {
                    label: "本次抄表期间", name: "BatchDate", width: 100, align: "left", sortable: false,
                    formatter: function (cellvalue, options, rowObject) {
                        return !!cellvalue ? cellvalue : $("#BatchDate").val();
                    }
                },
                {
                    label: "本次抄表时间", name: "ScaleDate", width: 100, align: "left", sortable: false,
                    formatter: function (cellvalue, options, rowObject) {
                        return !!cellvalue ? cellvalue : "@DateTime.Now.ToString("yyyy-MM-dd")";
                    }
                },
                { label: "本次抄表读数", name: "ScaleNum", width: 100, align: "left", sortable: false },
                { label: "用量", name: "Volume", width: 100, align: "left", sortable: false },
                {
                    label: "调整用量", name: "AdjustVolume", width: 100, align: "left", sortable: false, formatter: function (cellvalue, options, rowObject) {
                        return !!cellvalue ? cellvalue : 0;
                    }
                },
                { label: "单价", name: "UnitPrice", width: 80, align: "left", sortable: false },
                { label: "金额", name: "Price", width: 100, align: "left", sortable: false },
            ],
            rowNum: "1000",
            rownumbers: true,
            shrinkToFit: false,
            gridview: true,
            hidegrid: false
        });
    }

    function aftersavefunc(rowid) {
        var rowData = $('#gridTable').jqGrid('getRowData', rowid);
        if (!!rowData["ScaleDate"] && !!rowData["ScaleNum"] && !!rowData["Volume"] && !!rowData["AdjustVolume"] && !!rowData["UnitPrice"] && !!rowData["Price"]) {
            $("#gridTable").setCell(rowid, "State", "2");
        } else { $("#gridTable").setCell(rowid, "State", "1"); }
    }

    function ValidateTvalue(value, name) {
        if (isNaN(value)) {
            return [false, name + "请输入数字"];
        }
        else return [true, ""];
    }

    function onInputUnitPrice(obj) {
        var Volume = $("#gridTable").jqGridRowValue("Volume");
        var UnitPrice = $(obj).val();
        var Price = toDecimal(Volume * UnitPrice);
        $(obj).parent().next().find("input").val(Price);
    }

    function onInputDateTime(date) {
        if ($(".editable").length > 0 && !$("#gridTable").jqGrid('saveRow', selectedRowIndex)) { return false; }
        var IDs = $("#gridTable").jqGrid("getDataIDs");
        $(IDs).each(function (i, n) {
            $("#gridTable").setCell(n, "ScaleDate", date);
        });
    }

    function onInputPrice() {
        if ($(".editable").length > 0 && !$("#gridTable").jqGrid('saveRow', selectedRowIndex)) { return false; }
        var IDs = $("#gridTable").jqGrid("getDataIDs");
        var data = $("#Price").val();
        $(IDs).each(function (i, n) {
            $("#gridTable").setCell(n, "UnitPrice", data);
            var rowData = $('#gridTable').jqGrid('getRowData', n);
            var Price = toDecimal(rowData["Volume"] * data);
            $("#gridTable").setCell(n, "Price", Price);
            if (!!rowData["ScaleDate"] && !!rowData["ScaleNum"] && !!rowData["Volume"] && !!rowData["AdjustVolume"] && !!rowData["UnitPrice"] && !!rowData["Price"]) {
                $("#gridTable").setCell(n, "State", "2");
            }
        });
    }

    function onInputScaleNum(obj) {
        var rowid = $('#gridTable').jqGrid('getGridParam', 'selrow');
        var LastScaleNum = $("#gridTable").jqGridRowValue("LastScaleNum");
        var Volume = toDecimal($(obj).val() - LastScaleNum);
        var UnitPrice = $(obj).parent().next().next().next().find("input").val();
        var Price = toDecimal(Volume * UnitPrice);
        $("#gridTable").setCell(rowid, "Volume", Volume);
        //$("#gridTable").setCell(rowid, "Price", Price);
        $(obj).parent().next().next().next().next().find("input").val(Price);
    }

    //新增
    function btn_add_Form() {
        var rowids = "";
        $($("#gridTable").jqGrid("getRowData")).each(function (i, t) {
            rowids += t.Id;
        });
        dialogOpen({
            id: "AddForm",
            title: "新增费表抄表",
            url: '/PropertyManage/CS_EnergyMeterReading/AddMeter?BatchDate=' + $("#BatchDate").val() + "&OrganizeId=" + _organizeid + "&rowids=" + rowids,
            width: "1100px",
            height: "800px",
            callBack: function (iframeId) {
                top.frames[iframeId].AcceptClick(function (data) {
                    var ids = $("#gridTable").getDataIDs();
                    var Index = !!ids[ids.length - 1] ? ids[ids.length - 1] : 1;
                    $(data).each(function (i, n) {
                        n["LastBatchDate"] = !!n["BatchDate"] ? n["BatchDate"] : "无";
                        n["EnergyMeterInstanceId"] = n["Id"];
                        n["LastScaleDate"] = n["ScaleDate"];
                        n["State"] = 1;
                        n["LastScaleNum"] = !!n["ScaleNum"] ? n["ScaleNum"] : 0;
                        n["UnitPrice"] = !!$("#Price").val() ? $("#Price").val() : 0;
                        $("#gridTable").jqGrid('addRowData', Index + i, n);
                    });
                });
            }
        });
    }

    //删除
    function btn_delete_Form() {
        var keyValue = $("#gridTable").getGridParam('selrow');
        if (keyValue) {
            dialogConfirm('注：您确定要移除吗？该操作将无法恢复？', function (r) {
                if (r) {
                    $("#gridTable").delRowData(keyValue);
                    dialogMsg("移除成功。", 1);
                }
            });

        } else {
            dialogMsg('请选择需要移除的数据！', 0);
        }
    }

    //加载审核记录
    function GetGridAudit() {
        var $gridTable = $("#gridTable2");
        $gridTable.jqGrid({
            url: "../../PropertyManage/CS_EnergyMeterReading/GetAudit?BillId=" + keyValue,
            datatype: "json",
            height: 110,
            autowidth: true,
            mtype: "POST",
            unwritten: false,
            colModel: [
                    { label: 'ID', name: 'Id', hidden: true },
                    { label: "级数", name: "Level", width: 200, align: "left", sortable: false },
                    {
                        label: "执行类别", name: "RoleType", width: 200, align: "left", sortable: false,
                        formatter: function (cellvalue, options, rowObject) {
                            switch (cellvalue) {
                                case 2: return "角色";
                                case 1: return "岗位";
                                default: return "";
                            }
                        }
                    },
                    {
                        label: "执行角色", name: "RoleId", width: 200, align: "left", sortable: false,
                        formatter: function (cellvalue, options, rowObject) {
                            switch (rowObject.RoleType) {
                                case 2: return !!cellvalue ? top.clientroleData[cellvalue]["FullName"] : "";
                                case 1: return !!cellvalue ? top.clientpostData[cellvalue]["FullName"] : "";
                                default: return "";
                            }
                        }
                    },
                    {
                        label: "审批结果", name: "AuditState", width: 200, align: "left", sortable: true,
                        formatter: function (cellvalue, options, rowObject) {
                            switch (cellvalue) {
                                case 2: return "不通过";
                                case 1: return "通过";
                                default: return "";
                            }
                        }
                    },
                    {
                        label: '审批人', name: 'AuditMan', width: 200, align: "left", sortable: false,
                    },
                    { label: "审批时间", name: "AuditTime", width: 200, align: "left", sortable: false },
                    { label: "审批意见", name: "AuditMemo", width: 310, align: "left", sortable: false }
            ],
            rowNum: "1000",
            rownumbers: true,
            shrinkToFit: false,
            gridview: true,
            hidegrid: false,
            gridComplete: function () {
                if ($("#State").attr("data-value") == "5")
                    GetIsShow();
            }
        });
    }

    function GetIsShow() {
        var obj = $("#gridTable2").jqGrid("getRowData");
        var Level = 1;
        $(obj).each(function (i, n) {
            if (!n["AuditTime"]) {
                if (Level > n["Level"])
                    Level = n["Level"];
            }
        });
        $.SetForm({
            url: "../../SystemManage/Setting/GetIsShow",
            param: { TypeName: "抄表单", Level: Level - 1 },
            dataType: "text",
            success: function (data) {
                var Audit = JSON.parse(data);
                var Html = "";
                if (Audit.OK) {
                    $("#AuditState").show();
                    NowLevel = Audit.NowLevel;
                    if (Audit.HasHandling == 1) {
                        var HandleConditionJson = JSON.parse(Audit.HandleConditionJson);
                        for (var i = 0; i < HandleConditionJson.length; i++) {
                            if (HandleConditionJson[i].Type == "1") {
                                Html += "<td class=\"formTitle\"><input id=\"" + HandleConditionJson[i].FieldId + "\" type=\"checkbox\" class=\"WorkAudit\" title=\"" + HandleConditionJson[i].FieldName + "\" /></td>";
                                Html += "<td class=\"formValue\" >" + HandleConditionJson[i].FieldName + "</td>";
                            }
                            if (HandleConditionJson[i].Type == "2") {
                                Html += "<td class=\"formTitle\">" + HandleConditionJson[i].FieldName + "<font face=\"宋体\">*</font></td>";
                                Html += "<td class=\"formValue\"><input id=\"" + HandleConditionJson[i].FieldId + "\" type=\"text\" class=\"form-control WorkAudit\" isvalid=\"yes\" checkexpession=\"NotNull\" title=\"" + HandleConditionJson[i].FieldName + "\" /></td>";
                            }
                        }
                        $("#WorkAudit").html(Html);
                        if (ShowType == 1) {
                            $("#WorkAudit").html("");
                        }
                    }
                }
                else
                    $("#AuditState").hide();
            }
        });
    }

    function GetGridOperatorMemo(data) {

        var $gridTable = $("#gridTable1");
        $gridTable.jqGrid({
            datatype: "json",
            height: $(window).height() - 71.5,
            autowidth: true,
            colModel: [
                        { label: '项目主键', name: 'Id', hidden: true },
                        { label: '业务类别', name: 'Type', width: 120, align: 'center', sortable: false },
                        { label: '操作人', name: 'FromOperateName', width: 120, align: 'center', sortable: false },
                        { label: '操作时间', name: 'Date', width: 200, align: 'center', sortable: false },
                        {
                            label: "操作内容", name: "Content", index: "Content", width: 700, align: "left", sortable: false,
                            formatter: function (cellvalue, options, rowObject) {
                                if (!!rowObject.ToOperateName)
                                    return "发起者：" + rowObject.FromOperateName + "，接受者：" + rowObject.ToOperateName + "<br/>" + cellvalue;
                                else
                                    return "发起者：" + rowObject.FromOperateName + "<br/>" + cellvalue;
                            }
                        },
            ],
            viewrecords: true,
            rownumbers: false,
            shrinkToFit: false,
            gridview: true
        });
        $gridTable[0].addJSONData(data);
    }

    function btn_Audit(AuditState) {
        var queryJson = $("#AuditState").GetWebControls(keyValue);
        var obj = $("#gridTable2").jqGrid("getRowData");
        var Level = 99999;
        $(obj).each(function (i, n) {
            if (!n["AuditTime"]) {
                if (Level > n["Level"])
                    Level = n["Level"];
            }
        })
        queryJson["AuditState"] = AuditState;
        queryJson["Level"] = Level;
        queryJson["BillId"] = keyValue;
        queryJson["AuditType"] = 0;
        $.SaveForm({
            url: "../../PropertyManage/CS_EnergyMeterReading/AuditForm?keyValue=" + keyValue,
            param: queryJson,
            loading: "正在保存数据...",
            success: function () {
                $("#gridTable2").resetSelection();
                $("#gridTable2").trigger("reloadGrid");
                if ($("#State").attr("data-value") == "5")
                    GetIsShow();
            }
        })
    }

    //保存表单
    function AcceptClick(type) {
        if (!$('#BaseInfo').Validform()) {
            return false;
        }
        if (type == 1) {
            if ($(".editable").length > 0 && !$("#gridTable").jqGrid('saveRow', selectedRowIndex, { "keys": true, "aftersavefunc": aftersavefunc })) { return false; };
            if (!$("#Date").val()) { dialogMsg("单据日期不允许为空", 0); return false; }
            if (!$("#BatchDate").val()) { dialogMsg("抄表期间不允许为空", 0); return false; }
            if (!$("#RightDate").val()) { dialogMsg("权责期间不允许为空", 0); return false; }
            var postData = $("#first").GetWebControls(keyValue);
            if (!!$("#SendMan").attr("title")) { postData["SendManId"] = $("#SendMan").attr("title"); }
            if (!!$("#ReceiveMan").attr("title")) { postData["ReceiveManId"] = $("#ReceiveMan").attr("title"); };
            if ($("#SendWay").attr("data-value") == 11 && !!$("#Person").attr("title")) { postData["SendManId"] = $("#Person").attr("title"); postData["SendMan"] = $("#Person").val(); }
            else if ($("#SendWay").attr("data-value") == 12 && !!$("#Person").attr("title")) {
                postData["SendManId"] = "@LeSoft.Application.Code.OperatorProvider.Provider.Current().UserId";
                postData["SendMan"] = "@LeSoft.Application.Code.OperatorProvider.Provider.Current().UserName";
                postData["SendDate"] = "@LeSoft.Util.Time.Now.Date";
                postData["ReceiveManId"] = $("#Person").attr("title");
                postData["ReceiveMan"] = $("#Person").val();
            }
            var obj = $("#gridTable").jqGrid("getRowData");
            $.SaveForm({
                url: "../../PropertyManage/CS_EnergyMeterReading/SaveForm?keyValue=" + keyValue,
                param: { "Bill": JSON.stringify(postData), "listJson": JSON.stringify(obj) },
                loading: "正在保存数据...",
                success: function (data) {
                    if (!!keyValue) RemoveTab('Form_' + $("#Code").val())
                    else RemoveTab('Form');
                }
            });
        } else {
            $.SaveForm({
                url: "../../PropertyManage/CS_EnergyMeterReading/SubmitForm?keyValue=" + keyValue,
                loading: "正在保存数据...",
                success: function (data) {
                    if (!!keyValue) RemoveTab('Form_' + $("#Code").val())
                    else RemoveTab('Form');
                }
            });
        }
    }

    function RemoveTab(id) {
        top.frames["tabs_iframe_EnergyReading"].contentWindow.$("#gridTable").resetSelection();
        top.frames["tabs_iframe_EnergyReading"].contentWindow.$("#gridTable").trigger("reloadGrid");
        var $tab = top.$(".tab-div");
        var $tabContent = top.$(".tab-div-content");
        var li_index = $tab.find('li').length;
        $tab.find("#" + id).parents('li').remove();
        $tabContent.find('#tabs_iframe_' + id).remove();
        $tab.find('li:eq(' + (li_index - 2) + ')').find('table td:eq(1)').trigger("click");
    }
</script>
<div id="wrapper" style="background: #fff;" class="bills">
    <div id="left-side">
        <ul>
            <li class="choose active">
                抄表
            </li>
            <li class="pay">
                审核记录
            </li>
            <li class="wrap">
                业务日志
            </li>
        </ul>
    </div>

    <div id="border">
        <div id="line" class="one"></div>
    </div>
    <div id="right-side" class="tab-content">
        <div id="first" class="tab-pane active">
            <div style="margin-left: 10px; margin-top: 20px; margin-right: 30px;" id="BaseInfo" class="tab-pane active">
                <div>
                    <table class="form">
                        <tr>
                            <th class="formTitle">所属机构<font face="宋体">*</font></th>
                            <td class="formValue">
                                <div id="OrganizeId" type="select" class="ui-select" isvalid="yes" checkexpession="NotNull"></div>
                            </td>
                            <th class="formTitle">单据编号<font face="宋体">*</font></th>
                            <td class="formValue">
                                <input id="Code" type="text" onblur="$.ExistField(this.id, '../../PropertyManage/CS_EnergyMeterReading/ExistCode')" class="form-control" isvalid="yes" />
                            </td>
                            <th class="formTitle">单据日期<font face="宋体">*</font></th>
                            <td class="formValue">
                                <input id="Date" type="text" class="form-control input-wdatepicker" value="@DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")" onfocus="WdatePicker({ dateFmt: 'yyyy-MM-dd HH:mm:ss' })" isvalid="yes" checkexpession="NotNull" />
                            </td>
                        </tr>
                        <tr>
                            <th class="formTitle">抄表期间<font face="宋体">*</font></th>
                            <td class="formValue">
                                <input id="BatchDate" type="text" class="form-control input-wdatepicker" value="@DateTime.Now.ToString("yyyyMM")" onfocus="WdatePicker({ dateFmt: 'yyyyMM' })" isvalid="yes" checkexpession="NotNull" />
                            </td>
                            <th class="formTitle">权责期间<font face="宋体">*</font></th>
                            <td class="formValue">
                                <input id="RightDate" type="text" class="form-control input-wdatepicker" value="@DateTime.Now.ToString("yyyyMM")" onfocus="WdatePicker({ dateFmt: 'yyyyMM' })" isvalid="yes" checkexpession="NotNull" />
                            </td>
                            <th class="formTitle">批次号<font face="宋体">*</font></th>
                            <td class="formValue">
                                <input id="BatchNo" type="text" class="form-control input-wdatepicker" disabled readonly value="@DateTime.Now.ToString("yyyyMMdd.mmss")" onfocus="WdatePicker({ dateFmt: 'yyyyMMdd.mmss' })" isvalid="yes" checkexpession="NotNull" />
                            </td>
                        </tr>
                        <tr>
                            <th class="formTitle">附加说明</th>
                            <td class="formValue" colspan="5">
                                <textarea id="Description" class="form-control " style="height: 50px;" isvalid="yes" checkexpession="IsScript"></textarea>
                            </td>
                        </tr>
                        <tr>
                            <th class="formTitle">单据状态</th>
                            <td class="formValue">
                                <div id="State" type="selectTree" disabled="disabled" readonly class="ui-select "></div>
                            </td>
                            <th class="formTitle">处理方式</th>
                            <td class="formValue">
                                <div id="SendWay" type="selectTree" class="ui-select " isvalid="yes" checkexpession="IsScript"></div>
                            </td>
                            <th class="formTitle on-line" hidden="hidden">派给</th>
                            <td class="formValue on-line" hidden="hidden">
                                <div class="input-group" style="width: 100%;">
                                    <input id="Person" type="text" class="form-control">
                                    <span class="input-group-btn ">
                                        <a onclick="DataItemSelect(1,this)" class="form-control" style="cursor: pointer"><i class="fa fa fa-book " style=" font-size: 20px; padding-right: 5px; padding-top: 3px; color: gray"></i></a>
                                    </span>
                                </div>
                            </td>
                        <tr>
                            <th class="formTitle">派单人:</th>
                            <td class="formValue">
                                <div class="input-group" style="width: 100%;">
                                    <input id="SendMan" type="text" placeholder="请输入派单人" class="form-control Offline" />
                                    <span class="input-group-btn ">
                                        <a onclick="DataItemSelect(2, this)" class="form-control Offline" style="cursor: pointer"><i class="fa fa fa-book" style=" font-size: 20px; padding-right: 5px; padding-top: 3px; color: gray"></i></a>
                                    </span>
                                </div>
                            </td>
                            <th class="formTitle">接单人:</th>
                            <td class="formValue">
                                <div class="input-group" style="width: 100%;">
                                    <input id="ReceiveMan" type="text" placeholder="请输入接单人" class="form-control Offline" />
                                    <span class="input-group-btn ">
                                        <a onclick="DataItemSelect(3, this)" class="form-control Offline" style="cursor: pointer"><i class="fa fa fa-book" style=" font-size: 20px; padding-right: 5px; padding-top: 3px; color: gray"></i></a>
                                    </span>
                                </div>
                            </td>
                        </tr>
                        <tr>
                            <th class="formTitle">派单时间</th>
                            <td class="formValue">
                                <input id="SendDate" type="text" placeholder="请输入派单时间" class="form-control input-wdatepicker Offline" onfocus="WdatePicker()" />
                            </td>
                            <th class="formTitle">接单时间:</th>
                            <td class="formValue">
                                <input id="ReceiveDate" type="text" placeholder="请输入接单时间" class="form-control input-wdatepicker Offline" onfocus="WdatePicker()" onchange="" />
                            </td>
                        </tr>
                        <tr style=" height: 20px; border-bottom: 1px dashed #cecece;"><td colspan="6"></td></tr>
                        <tr style="height: 36px;">
                            <td colspan="2">
                                <div class="toolbar">
                                    <a id="lr-addForm" class="btn btn-success btn-xs" onclick="btn_add_Form()"><i class="fa fa-plus"></i>&nbsp;新增</a>
                                    @*<a id="lr-editForm" class="btn btn-info btn-xs" onclick="btn_edit_Form()" hidden="hidden"><i class="fa fa-pencil-square-o"></i>&nbsp;编辑</a>*@
                                    <a id="lr-deleteForm" class="btn btn-danger btn-xs" onclick="btn_delete_Form()"><i class="fa fa-trash-o"></i>&nbsp;删除</a>
                                </div>
                            </td>
                            <td class="formTitle Batch" hidden="hidden">抄表时间</td>
                            <td class="Batch formValue" hidden="hidden">
                                <input id="BatchDateTime" type="text" onfocus="WdatePicker({ onpicking: function (dq) { onInputDateTime(dq.cal.getNewDateStr()); }})" class="form-control input-wdatepicker" value="@DateTime.Now.ToString("yyyy-MM-dd")" />
                            </td>
                            <td class="formTitle Batch" hidden="hidden">单价</td>
                            <td class="Batch formValue" hidden="hidden">
                                <input id="Price" type="number" class="form-control" onpropertychange="onInputPrice()" oninput="onInputPrice()" value="0" />
                            </td>
                        </tr>
                        <tr style=" height: 0px; border-bottom: 1px dashed #cecece;"><td colspan="6"></td></tr>
                        <tr>
                            <td colspan="6">
                                <div class="panel-Title" style="border:0px;">工作内容</div>
                                <table id="gridTable"></table>
                            </td>
                        </tr>
                    </table>
                </div>
            </div>
        </div>
        <div id="second" class="tab-pane">
            <div id="ExpandInfo" style=" margin-right: 15px">
                <table style="padding-left:5px;padding-top:5px;">
                    <tr style="padding-left: 5px; padding-top: 5px; margin-left: 5px; margin-top: 5px;"><td colspan="6" style="padding-left: 5px; padding-top: 5px;"><table id="gridTable2"></table></td></tr>
                    <tr id="AuditState" hidden style="padding-left:5px;padding-top:5px;margin-left:5px;margin-top:5px;">
                        <td class="formTitle" style="padding-left: 5px; padding-top: 5px;">审批意见：</td>
                        <td class="formValue" colspan="3" style="padding-left: 5px; padding-top: 5px;"><input id="AuditMemo" class="form-control" type="text" /></td>
                        <td class="formValue" colspan="2" style="padding-left: 5px; padding-top: 5px;">
                            <a id="lr-addRule" class="btn btn-success btn-xs" style="width:150px;height:28px;" onclick="btn_Audit(1)"><i class="fa fa-plus"></i>&nbsp;同意</a>
                            <a id="lr-deleteRule" class="btn btn-danger btn-xs" style="width: 150px; height: 28px;" onclick="btn_Audit(2)"><i class="fa fa-trash-o"></i>&nbsp;不同意</a>
                        </td>
                    </tr>
                </table>
            </div>
        </div>
        <div id="third" class="tab-pane">
            <div class="gridPanel" style="padding-left:5px;padding-top:5px;width:100%;overflow-y: scroll;">
                <table id="gridTable1"></table>
            </div>
        </div>

        @*<div id="fourth" class="tab-pane">

            </div>*@
    </div>
    <script>

        $('.choose').click(function () {
            $('.choose').addClass('active');
            $('.pay').removeClass('active');
            $('.wrap').removeClass('active');
            $('.ship').removeClass('active');
            $('#line').addClass('one');
            $('#line').removeClass('two');
            $('#line').removeClass('three');
            $('#line').removeClass('four');
            $('#first').addClass('active');
            $('#second').removeClass('active');
            $('#third').removeClass('active');
            $('#fourth').removeClass('active');
        });
        $('.pay').click(function () {
            $('.pay').addClass('active');
            $('.choose').removeClass('active');
            $('.wrap').removeClass('active');
            $('.ship').removeClass('active');
            $('#line').addClass('two');
            $('#line').removeClass('one');
            $('#line').removeClass('three');
            $('#line').removeClass('four');
            $('#first').removeClass('active');
            $('#second').addClass('active');
            $('#third').removeClass('active');
            $('#fourth').removeClass('active');
        });
        $('.wrap').click(function () {
            $('.wrap').addClass('active');
            $('.pay').removeClass('active');
            $('.choose').removeClass('active');
            $('.ship').removeClass('active');
            $('#line').addClass('three');
            $('#line').removeClass('two');
            $('#line').removeClass('one');
            $('#line').removeClass('four');
            $('#first').removeClass('active');
            $('#second').removeClass('active');
            $('#third').addClass('active');
            $('#fourth').removeClass('active');
        });

    </script>

</div>

<div id="bottomField">
    <a id="save" class="btn btn-default" style="background-color: #27c24c; border: 1px solid #4cae4c;color:#fff; " onclick="AcceptClick(1)">保存单据</a>
    <a id="submit" class="btn btn-default" onclick="AcceptClick(2)" style="display: none; background-color: #27c24c; border: 1px solid #4cae4c; color: #fff;">提交单据</a>
</div>
